package org.sgx.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;

import org.sgx.dao.util.SQLUtil;
import org.sgx.dao.util.Util;

//import com.beeblos.portlet.events.util.SQLUtil;
//import com.beeblos.portlet.events.util.Util;

/**
 * this does the same as JDBCConnectionGiver but always tray to use the same connection object
 * connectionMustClose()==false
 */
public class JDBCConnectionGiverNoClose implements ConnectionGiver {

	String url, userName, password, dbName, driver;
	Connection conn = null;	
	private SQLUtil sql;
	
	public JDBCConnectionGiverNoClose(String url, String driver, String dbName,
			String userName, String password) throws DaoException {
		super();
		this.url = url;
		this.driver = driver;
		this.dbName = dbName;
		this.userName = userName;
		this.password = password;		
	}

	public Connection getConnection() throws DaoException {
		try {
			if (conn == null || conn.isClosed()){//.isValid(0)) {
				Class.forName(driver).newInstance();
				conn = DriverManager.getConnection(url + dbName, userName, password);
			}
			return conn;
		} catch (Exception e) {
			throw new DaoException(e);
		}
	}	

	public boolean connectionMustClose() {
		return false;
	}
	
}
